package com.shop.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.shop.constant.MessageConstant;
import com.shop.entity.Result;
import com.shop.pojo.Orders;
import com.shop.service.OrdersService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/orders")
@Api(tags = "订单管理")
public class OrdersController {
    @Reference
    private OrdersService ordersService;

    @PostMapping("/add")
    @ApiOperation("添加订单接口")
    public Result add(@RequestBody Orders orders){
        Orders O=ordersService.add(orders);
        return new Result(true, MessageConstant.ADD_SUCCESS,O);
    }

    @GetMapping("/findAll")
    @ApiOperation("显示用户全部订单接口")
    @ApiImplicitParams({@ApiImplicitParam(dataType = "int",name = "uid",value = "用户id",required = true,example = "0"),@ApiImplicitParam(dataType = "int",name = "pagenum",value = "页数",required = true,example = "0"),@ApiImplicitParam(dataType = "int",name = "pagesize",value = "每页显示条数",required = true,example = "0")})
    private Result findAll(@RequestParam(value = "uid",required = true) Integer uid,
                           @RequestParam(value = "currentPage",required = true) Integer pagenum,
                           @RequestParam(value = "pageSize",required = true) Integer pagesize){
        Page<Orders> page=ordersService.getPage(uid, pagenum, pagesize);
        return new Result(true, MessageConstant.QUERY_SUCCESS,page);
    }
}
